package com.example.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.model.domain.HousingInfrastructure;
import com.example.mybatisplus.mapper.HousingInfrastructureMapper;
import com.example.mybatisplus.model.dto.PageDTO;
import com.example.mybatisplus.service.HousingInfrastructureService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ablbb
 * @since 2024-07-19
 */
@Service
public class HousingInfrastructureServiceImpl extends ServiceImpl<HousingInfrastructureMapper, HousingInfrastructure> implements HousingInfrastructureService {

    // 无妨先试试这种简单的判定方法
    @Override
    public Page<HousingInfrastructure> pageList(HousingInfrastructure housingInfrastructure, PageDTO dto) {
        QueryWrapper<HousingInfrastructure> wrapper=new QueryWrapper<>();
        if(StringUtils.isNotBlank(housingInfrastructure.getParkArea())){
            wrapper.like("parkArea",housingInfrastructure.getParkArea());
        }
        if(StringUtils.isNotBlank(housingInfrastructure.getCampus())){
            wrapper.like("campus",housingInfrastructure.getCampus());
        }
        if(Objects.nonNull(housingInfrastructure.getNumber())){
            wrapper.eq("number",housingInfrastructure.getNumber());
        }
        Page<HousingInfrastructure> page=new Page<>();
        page.setCurrent(dto.getPageNo()).setSize(dto.getPageSize());
        baseMapper.selectPage(page,wrapper);
        return page;
    }
}
